import request from "@/utils/request";
import { encryption } from "@/utils/jsencrypt";

export function useInfoApi() {
  return {
    // 获取token接口
    getToken: (params: any) => {
      const grantType = "password";
      const scope = "server";
      const user = encryption({
        data: params,
        key: "1234567891234567",
        param: ["password"],
        type: "AES",
      });
      return request({
        url: `/auth/oauth/token?username=${encodeURIComponent(
          user.username
        )}&password=${user.password}&randomStr=${user.randomStr}&code=${
          user.code
        }&grant_type=password&scope=server`,
        header: {
          isToken: false,
          withoutToken: true,
          Authorization: "Basic YWRtaW46YWRtaW4=",
        },
        method: "POST",
      });
    },
    // 获取用户信息
    getUserInfo: () => {
      return request({
        url: "/upms/user/info",
        method: "GET",
      });
    },
    signOut: () => {
      return request({
        url: "/auth/token/logout",
        method: "DELETE",
      });
    },
    // 修改密码
    userEdit: (params: object) => {
      return request({
        url: "/upms/user/edit",
        method: "PUT",
        data: params,
      });
    },
  };
}
